home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Initialize.c
-
- Contains: Initialization code for this application
-
- Written by: Chris White, Developer Technical Support
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- 9/28/95 CW First release
-
- */
-
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __TEXTEDIT__
- #include <TextEdit.h>
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #ifndef __OSEVENTS__
- #include <OSEvents.h>
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __SEGLOAD__
- #include <SegLoad.h>
- #endif
-
- #ifndef __DRAG__
- #include <Drag.h>
- #endif
-
- #ifndef __CODEFRAGMENTS__
- #include <CodeFragments.h>
- #endif
-
-
-
- #ifndef __FRAGMENTTOOL__
- #include "FragmentTool.h"
- #endif
-
- #ifndef __MENUSTUFF__
- #include "MenuStuff.h"
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
- #ifndef __PROTOTYPES__
- #include "Prototypes.h"
- #endif
-
-
-
-
- const int32 kSleepTime = 60L;
-
-
- void InitToolbox ( void )
- {
- InitGraf ( &qd.thePort );
- InitFonts ( );
- InitWindows ( );
- InitMenus ( );
- TEInit ( );
- InitDialogs ( nil );
- InitCursor ( );
-
- FlushEvents ( everyEvent, 0 );
-
- return;
- }
-
-
-
- void InitApplication ( void )
- {
- SetMenuBar ( GetNewMBar ( kMenuBarID ) );
- AddResMenu ( GetMHandle ( kAppleMenu ), 'DRVR' );
- DrawMenuBar ( );
-
- if ( !CheckConfiguration ( ) )
- {
- AlertUser ( kNeedSystem7, 0, nil );
- ExitToShell ( );
- }
-
- gQuit = false; // Initialize flag that controls main event loop
-
- // We need to get null events often enough to blink the caret correctly
- gSleepTime = (GetCaretTime ( ) < kSleepTime) ? GetCaretTime ( ) : kSleepTime;
-
-
- InitListClickLoop ( ); // Creates the UPPs (etc) for the ClickLoop
- InitDragHandlers ( ); // Creates the UPPs for the Drag Handlers
- InstallAppleEventHandlers ( ); // Installs the AE handlers for the required AE
-
- AdjustMenus ( );
-
- // Create any other RoutineDescriptors we may need
- gOutlineUserItemUPP = NewUserItemProc ( OutlineUserItem );
-
- return;
- }
-
-
-
-
-
- //
- // We'll limit the scope of some of our function to the current source file
- // by declairing them static. Although this has limited advantages as
- // far as encapsulation is concerned, it can make the source code a little
- // more readable.
- //
- static Boolean CheckConfiguration ( void )
- {
- long theResult;
- OSErr theErr;
- Boolean bHasAppleEvents, bHasFSpTraps, bHasFSpStdFile, bHasCodeFragmentManager;
-
-
- // Verify that we can run on the current configuration
-
- // We require AppleEvent Manager and FSSpec-based file traps and Standard File
- theErr = Gestalt ( gestaltAppleEventsAttr, &theResult );
- bHasAppleEvents = (theErr == noErr && (theResult & (1L << gestaltAppleEventsPresent)));
-
- theErr = Gestalt ( gestaltFSAttr, &theResult );
- bHasFSpTraps = (theErr == noErr && (theResult & (1L << gestaltHasFSSpecCalls)));
-
- theErr = Gestalt ( gestaltStandardFileAttr, &theResult );
- bHasFSpStdFile = (theErr == noErr && (theResult & (1L << gestaltStandardFile58)));
-
- // Ensure CFM or CFM-68K is available
- theErr = Gestalt ( gestaltCFMAttr, &theResult );
- bHasCodeFragmentManager = (theErr == noErr && (theResult & (1L << gestaltCFMPresent)));
-
- // We would also like the Drag Manager
- theErr = Gestalt ( gestaltDragMgrAttr, &theResult );
- gHasDragManager = (theErr == noErr && (theResult & (1L << gestaltDragMgrPresent)));
-
-
- // It isn't enough to use Gestalt because we may not have sucessfully linked
- // to the DragLib shared library. So, we also need to test one of the symbols
- // against kUnresolvedSymbol to make sure we have a valid connection to it.
- // Things like memory limitations to someone having the thing open with
- // write permission could cause it to fail.
-
- #if GENERATINGCFM
- if ( gHasDragManager )
- gHasDragManager = (InstallTrackingHandler != (void*) kUnresolvedSymbolAddress);
- #endif
-
- return (bHasAppleEvents & bHasFSpTraps & bHasFSpStdFile & bHasCodeFragmentManager);
- }
-
-
-
-
-